﻿//-----------------------------------------------------------------------
// <copyright file="ThreadDataContractUnitTest.cs" company="CodePlex">
//     Copyright (c) Doug Holland, CodePlex. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace CodePlex.Diagnostics.Contracts
{
    using System;
    using System.Threading;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Provides unit tests for the <see cref="T:CodePlex.Diagnostics.Contracts.ThreadDataContract"/> class.
    /// </summary>
    [TestClass]
    public sealed class ThreadDataContractUnitTest
    {
        #region public ThreadDataContractUnitTest()

        /// <summary>
        /// Initializes a new instance of the <see cref="T:ThreadDataContractUnitTest"/> class.
        /// </summary>
        public ThreadDataContractUnitTest()
        {
        }

        #endregion

        #region public TestContext TestContext

        /// <summary>
        /// Gets or sets the test context which provides information about and functionality for the current test run.
        /// </summary>
        public TestContext TestContext
        {
            get;
            set;
        }

        #endregion

        #region public void ThreadDataContractConstructorUnitTest()

        /// <summary>
        /// Ensures that the constructor of the <see cref="T:CodePlex.Diagnostics.Contracts.ThreadDataContract"/> class is correctly copying the values from the supplied <see cref="T:System.Reflection.Assembly"/> instance.
        /// </summary>
        [TestMethod]
        public void ThreadDataContractConstructorUnitTest()
        {
            Thread currentThread = Thread.CurrentThread;

            ThreadDataContract thread = new ThreadDataContract(currentThread);

            Assert.AreEqual<bool>(thread.IsAlive, currentThread.IsAlive, "Serialized Thread contains an invalid Boolean value for IsAlive.");
            Assert.AreEqual<bool>(thread.IsBackground, currentThread.IsBackground, "Serialized Thread contains an invalid Boolean value for IsBackground.");
            Assert.AreEqual<bool?>(thread.IsThreadPoolThread, currentThread.IsThreadPoolThread, "Serialized Thread contains an invalid Boolean value for IsThreadPoolThread.");
            Assert.AreEqual<int>(thread.ManagedThreadId, currentThread.ManagedThreadId, "Serialized Thread contains an invalid ManagedThreadId.");
            Assert.AreEqual<string>(thread.Name, currentThread.Name, "Serialized Thread contains an invalid Name.");
            Assert.AreEqual<string>(thread.ThreadPriority, currentThread.Priority.ToString(), "Serialized Thread contains an invalid Priority.");
            Assert.AreEqual<string>(thread.ThreadState, currentThread.ThreadState.ToString(), "Serialized Thread contains an invalid ThreadState.");
        }

        #endregion
    }
}
